package com.example.administrator.newsapp.Fragments;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;


import com.example.administrator.newsapp.DialogManagers.EditDialog;
import com.example.administrator.newsapp.R;
import com.example.administrator.newsapp.StatusBarUtils.SetActionBarColor;
import com.example.administrator.newsapp.StatusBarUtils.SetActionBarHeight;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

public class NewsFragment extends Fragment {
    private final String[] mTitles={"关注","推荐","科技","成都","娱乐","社会"};
    private ArrayList<Fragment> mFragments=new ArrayList<>();
    private MyPageAdapter myPageAdapter;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final View view=inflater.inflate(R.layout.activity_news,null);
        SetActionBarHeight setActionBarHeight=new SetActionBarHeight(view,R.id.actionbar_bcg);
        SetActionBarColor setActionBarColor=new SetActionBarColor(view,R.id.actionbar_bcg);

        ViewPager viewPager=(ViewPager) view.findViewById(R.id.viewpage_summary);
        SlidingTabLayout st=(SlidingTabLayout) view.findViewById(R.id.st);

        for (String title:mTitles){
            mFragments.add(SummaryFragment.getTitle(title));

        }
        myPageAdapter=new MyPageAdapter(getChildFragmentManager());
        viewPager.setAdapter(myPageAdapter);
        st.setViewPager(viewPager);
        //设置编辑dialog，弹出dialog

        Button editorDialog=(Button)view.findViewById(R.id.bt_editorDialog);
        editorDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Log.i("TTTT","editdialog");
                EditDialog dialog=new EditDialog(getContext());
                dialog.showEditDialog();

            }
        });
        return view;
    }

    private class MyPageAdapter extends FragmentPagerAdapter{
        public MyPageAdapter(FragmentManager fm) {
            super(fm);
        }

        public int getCount() {
            return mFragments.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        public Fragment getItem(int i) {
            return mFragments.get(i);
        }
    }

}
